package com.hula.onion.book.server.spider.platforms.qianpenwang;

import com.hula.onion.book.server.common.CommonResponse;
import com.hula.onion.book.server.common.SpiderCommon;
import com.hula.onion.book.server.config.ResponseStatusEnum;
import com.hula.onion.book.server.utils.HttpUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created by work on 2018/1/31.
 */
@Component("qianPenWangSpider")
public class QianPenWangSpider extends SpiderCommon {
    @Autowired
    private QianPenWangSpiderHelper spiderHelper;

    private static final String LOGIN_URL = "https://www.qianpen.com/edasapp/app/index/login.do";

    @Override
    public CommonResponse execute() {
        String loginStr = HttpUtils.get(LOGIN_URL,
                spiderHelper.installRequestParams(loginForm),
                getHttpContext());
        if (StringUtils.isEmpty(loginStr)) {
            return new CommonResponse(ResponseStatusEnum.FAIL);
        }
        return spiderHelper.parseAccountBalance(loginStr);
    }
}
